
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Collections.Generic;
using System.Text;

using Swaf;
using Swaf.BizObj;
using Swaf.Gui;
using Swaf.Security;
namespace eCom.Gui
{
	public class eComBundledProductBizProc : Articles.Gui.ArticleManagementBizProc
	{
		public eComBundledProductBizProc(ActiveBizProc procState) : base(procState) { }

		protected void createProdAssociation(object articleInfo)
		{
			if (articleInfo != null)
			{
				Swaf.BGuid.Guid pid = m_procState.get("pid") as Swaf.BGuid.Guid;
				Swaf.BGuid.Guid articleId =(Swaf.BGuid.Guid) articleInfo;
				IResults rc = App.ruleMgr.execute("addAssociationToArticle", pid, articleId);
				if (rc.ExceptionInfo != null)
					displayMessageFromBizRuleException("Error-CannotAssociateProduct", rc.ExceptionInfo);
			}
		}
		protected override void setupRuleNames()
		{
			base.setupRuleNames();
			m_getBizObjListRule = "getArticlesAssociatedWithId";
		}
		protected override object[] getBizObjListRuleParameters(object parentId, IBizObj filterSort)
		{
			Swaf.BGuid.Guid pid = m_procState.get("pid") as Swaf.BGuid.Guid;
			string an = m_procState.get("associationName").ToString();
			return new object[] { an, pid };
		}
		protected override void setupActions()
		{
			base.setupActions();
			Actions.addAction(new GenericAction("CreateProductAssociation", true, (CurrentEditPrivilege > Privileges.Edit), this, new ActionParamTrigger(createProdAssociation), new object[] { }));
		}
		public override void updateActionState()
		{
			base.updateActionState();
			((GenericAction)Actions["CreateProductAssociation"]).Availability = CanEdit ? ActionAvailability.enabled : ActionAvailability.none;
		}
		public override Privileges CurrentEditPrivilege
		{
			get { return CurrentPrincipal.getPrivilege("AppFunctions.ManageProducts"); }
		}

	}
}
